package cn.sunxyz.spider.sample.zhihu;

import cn.sunxyz.spider.Page;
import cn.sunxyz.spider.pipeline.Pipeline;
import org.jsoup.nodes.Document;
import us.codecraft.xsoup.Xsoup;

import java.util.List;

/**
 * Created by yangrd on 2018/6/14
 **/
public class ZhiHuPipeline implements Pipeline<Object> {
    @Override
    public void process(Object title, Page page) {
        Document document = page.getDocument();
        String flower = document.select(".NumberBoard-itemValue").first().text();
        String watch = document.select(".NumberBoard-itemValue").last().text();
        List<String> answer = Xsoup.compile("//div[@class='List-item']/allText()").evaluate(document).list();
        save(new ZhiHu(page.getRequest(), title.toString(), flower, watch, answer));
    }

    void save(ZhiHu zhiHu) {
        // TODO 持久化到数据库
    }
}
